<extend name="./public/frame.html"/>
<block name="content">
    <style>
        .layui-form-label{width: 12%;}
        .layui-input-block{margin-left: 12%;}
    </style>
    <form class="layui-form layui-form-pane1" id="testForm" method="post" enctype="multipart/form-data">
        <table class="layui-table">
            <tr>
                <td style="text-align: center;width: 15%">投诉内容</td>
                <td><input type="text" name="complain_message" id="complain_message" lay-verify="required" placeholder="投诉内容" class="layui-input" style="width: 500px;" onkeyup="strleng(this)"></td>
            </tr>
            <tr>
                <td style="text-align: center;width: 15%">所属类型</td>
                <td>
                    <div class="layui-input-inline" style="width: 200px;">
                        <select name="order_type" lay-filter="order_type" id="is_recommed">
                            <?php foreach($orderTypeList as $key=>$value):?>
                            <option value="<?php echo $key;?>"><?php echo $value;?></option>
                            <?php endforeach;?>
                        </select>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="text-align: center;width: 15%">所属应用</td>
                <td>
                    <div class="layui-input-inline" style="width: 200px;">
                        <select name="user_or_driver" lay-filter="user_or_driver" id="user_or_driver">
                            <?php foreach($appTypeList as $key=>$value):?>
                            <option value="<?php echo $key;?>"><?php echo $value;?></option>
                            <?php endforeach;?>
                        </select>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="text-align: center;width: 15%">排序（按从小到大排序）</td>
                <td><input type="text" name="sort" id="sort" lay-verify="required" value="0" placeholder="0" value="1" class="layui-input" style="width: 500px;"></td>
            </tr>
            <tr>
                <td colspan="3" style="padding-left: 100px;">
                    <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </td>
            </tr>
        </table>
    </form>
    <script>
        layui.use(['form'], function () {
            form = layui.form;
            form.on('submit(*)', function(data){
                $.ajax({
                    url:'{:url("/admin/ComplainMessage/add")}',
                    async:true,
                    dataType:'json',
                    type:'POST',
                    data: $(data.form).serialize(),
                    success:function(res){
                        if(res.code==1){
                            layer.alert(res.msg, {icon: 6},function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                window.parent.location.reload()
                            });
                        }else{
                            layer.msg(res.msg,{icon: 5});
                        }
                    }
                });
                return false;
            });
        });
        //验证只能输入不能超过16个字符
        function strleng(object) {
            var value   = object.value;
            var id      = object.id;
            var cArr = value.match(/[^\x00-\xff]/ig);
            var num = value.length + (cArr == null ? 0 : cArr.length);
            if(num > 16){
                layer.msg('请输入不要超过16个字符',{icon: 5});
                $("#"+id).val('');
                return false;
            }
        }
    </script>
</block>
